OUTDIR = output
OUTFILES = $(OUTDIR)/test-d_dmd $(OUTDIR)/test-d_ldc $(OUTDIR)/test-nim $(OUTDIR)/test-zig $(OUTDIR)/test-v $(OUTDIR)/test-rust $(OUTDIR)/test-cpp_gcc $(OUTDIR)/test-c_tcc $(OUTDIR)/test-c_gcc $(OUTDIR)/test-cpp_clang $(OUTDIR)/test-c_clang

all: $(OUTFILES) 

strip: $(OUTFILES)
	strip $(OUTDIR)/test-zig 
	strip $(OUTDIR)/test-nim 
	#strip $(OUTDIR)/test-v # Why does this fail on the v binary? 
	strip $(OUTDIR)/test-rust 
	strip $(OUTDIR)/test-cpp_gcc 
	strip $(OUTDIR)/test-c_gcc 
	strip $(OUTDIR)/test-c_tcc 
	strip $(OUTDIR)/test-cpp_clang 
	strip $(OUTDIR)/test-c_clang
	strip $(OUTDIR)/test-d_dmd
	strip $(OUTDIR)/test-d_ldc

time: $(OUTFILES)
	for FILE in $(shell ls $(OUTDIR)); do
		time ./${FILE}
	done

$(OUTDIR)/test-zig: $(OUTDIR)
	zig build-exe -O ReleaseSmall main.zig --name test-zig
	mv test-zig $(OUTDIR)/ # Why can't I change the output directory?

$(OUTDIR)/test-v: $(OUTDIR)
	~/.local/bin/v/v -b native main.v -o $(OUTDIR)/test-v

$(OUTDIR)/test-rust: $(OUTDIR)
	rustc main.rs -o $(OUTDIR)/test-rust

$(OUTDIR)/test-nim: $(OUTDIR)
	nim c -o:$(OUTDIR)/test-nim --opt:size -d:release main.nim

$(OUTDIR)/test-cpp_gcc: $(OUTDIR)
	g++ -Os main.cpp -o $(OUTDIR)/test-cpp_gcc

$(OUTDIR)/test-c_tcc: $(OUTDIR)
	tcc -Os main.c -o $(OUTDIR)/test-c_tcc

$(OUTDIR)/test-c_gcc: $(OUTDIR)
	gcc -Os main.c -o $(OUTDIR)/test-c_gcc

$(OUTDIR)/test-cpp_clang: $(OUTDIR)
	clang++ -Os main.cpp -o $(OUTDIR)/test-cpp_clang

$(OUTDIR)/test-c_clang: $(OUTDIR)
	clang -Os main.c -o $(OUTDIR)/test-c_clang

$(OUTDIR)/test-d_dmd: $(OUTDIR)
	dmd -O main.d -of=$(OUTDIR)/test-d_dmd

$(OUTDIR)/test-d_ldc: $(OUTDIR)
	ldc2 -Oz main.d -of=$(OUTDIR)/test-d_ldc

$(OUTDIR):
	mkdir $(OUTDIR)

clean:
	rm -rf zig-cache $(OUTDIR)

